<?php
@include('include/common.inc.php');	
$keyword = $_REQUEST['keyword'];
$type = $_REQUEST['type'];

$query1 = "select * from $TBL_NEWS where state=2 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
$res1 = mysql_query($query1);
$num1 = mysql_num_rows($res1);

$query2 = "select * from $TBL_NEWS where state=1 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
$res2 = mysql_query($query2);
$num2 = mysql_num_rows($res2);

$query3 = "select * from $TBL_NEWS0 where cate_id=18 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
$res3 = mysql_query($query3);
$num3 = mysql_num_rows($res3);

$query4 = "select * from $TBL_NEWS0 where cate_id=19 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
$res4 = mysql_query($query4);
$num4 = mysql_num_rows($res4);

$query5 = "select * from $TBL_NEWS0 where cate_id in (4,5,6,7) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
$res5 = mysql_query($query5);
$num5 = mysql_num_rows($res5);

$query6 = "select * from $TBL_NEWS0 where cate_id in (8,9,10,11,12) and ch_headline like '%$keyword%'";
$res6 = mysql_query($query6);
$num6 = mysql_num_rows($res6);

$query7 = "select * from $TBL_NEWS0 where cate_id in (13,14,15,16,17) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
$res7 = mysql_query($query7);
$num7 = mysql_num_rows($res7);

$query8 = "select * from $TBL_HOUSE where  del=0 and (num like '%$keyword%' or address like '%$keyword%'   or hou_name  like '%$keyword%')";
$res8 = mysql_query($query8);
$num8 = mysql_num_rows($res8);


if($type==1)
{
	$query = "select * from $TBL_NEWS where state=2 and ch_headline like '%$keyword%' or ch_text like '%$keyword%'   order by id desc";
	$type='生活情報';
	$url = "new.php?id=";
}elseif($type==2){
	$query = "select * from $TBL_NEWS where state=1 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
	$type='活動訊息';
	$url = "new.php?id=";
}elseif($type==3){
	$query = "select * from $TBL_NEWS0 where cate_id=18 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
	$type='產業新聞';
	$url = "new0.php?id=";
}elseif($type==4){
	$query = "select * from $TBL_NEWS0 where cate_id=19 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
	$type='居家生活';
	$url = "new0.php?id=";
}elseif($type==5){
	$query = "select * from $TBL_NEWS0 where cate_id in (4,5,6,7) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
	$type='租屋注意事項';
	$url = "notes3.php?id=";
}elseif($type==6){
	$query = "select * from $TBL_NEWS0 where cate_id in (8,9,10,11,12) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
	$type='買房五步驟';
	$url = "step3.php?id=";
}elseif($type==7){
	$query = "select * from $TBL_NEWS0 where cate_id in (13,14,15,16,17) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
	$type='賣房五步驟';
	$url = "sellersstep3.php?id=";
}elseif($type==8){
	$query = "select * from $TBL_HOUSE where del=0 and (num like '%$keyword%' or address like '%$keyword%'  or hou_name  like '%$keyword%')  order by id desc";
	$type='房屋信息';
	$url = "goods.php?id=";
}else{
	if($num1>0)
	{
		$query = "select * from $TBL_NEWS where state=2 and ch_headline like '%$keyword%' or ch_text like '%$keyword%'   order by id desc";
		$type='生活情報';
		$url = "new.php?id=";
	}elseif($num2>0){
		$query = "select * from $TBL_NEWS where state=1 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
		$type='活動訊息';
		$url = "new.php?id=";
	}elseif($num3>0){
		$query = "select * from $TBL_NEWS0 where cate_id=18 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
		$type='產業新聞';
		$url = "new0.php?id=";
	}elseif($num4>0){
		$query = "select * from $TBL_NEWS0 where cate_id=19 and ch_headline like '%$keyword%' or ch_text like '%$keyword%' order by id desc";
		$type='居家生活';
		$url = "new0.php?id=";
	}elseif($num5>0){
		$query = "select * from $TBL_NEWS0 where cate_id in (4,5,6,7) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
		$type='租屋注意事項';
		$url = "notes3.php?id=";
	}elseif($num6>0){
		$query = "select * from $TBL_NEWS0 where cate_id in (8,9,10,11,12) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
		$type='買房五步驟';
		$url = "step3.php?id=";
	}elseif($num7>0){
		$query = "select * from $TBL_NEWS0 where cate_id in (13,14,15,16,17) and ch_headline like '%$keyword%' or ch_text like '%$keyword%'";
		$type='賣房五步驟';
		$url = "sellersstep3.php?id=";
	}elseif($num8>0){
		$query = "select * from $TBL_HOUSE where del=0 and (num like '%$keyword%' or address like '%$keyword%'  or hou_name  like '%$keyword%')  order by id desc";
		$type='房屋信息';
		$url = "goods.php?id=";
	}		
}

//

$cur_page = (int)$_GET["p"];   //获取当前页
$url_param = preg_replace("/(p=[0-9]+)&/", "", $_SERVER['QUERY_STRING']);
$pages = new Pager($query, $cur_page, 10, $url_param);
$page_string = $pages -> getPageString();  
if(empty($page_string)) $page_string='暫無！';
$result = $pages -> getRsPerPage();	
while($rows = $db->fetch_array($result))
{
	if($_REQUEST['type']==8)
	{
		$rows['ch_headline']= $rows['cate_name'].$rows['address'];
	}
	$rowsearch[] = $rows;

}
@include('number.php');//验证码
$smarty->assign("rowsearch",$rowsearch);
$smarty->assign("keyword",$keyword);
$smarty->assign("type",$type);
$smarty->assign("url",$url);
$smarty->assign("page_string",$page_string);
$smarty->assign("num1",$num1);
$smarty->assign("num2",$num2);
$smarty->assign("num3",$num3);
$smarty->assign("num4",$num4);
$smarty->assign("num5",$num5);
$smarty->assign("num6",$num6);
$smarty->assign("num7",$num7);
$smarty->assign("num8",$num8);
$smarty->display('keyword.html');
?>